import request from '@/config/request'
import qs from 'qs'
import { userApi } from './api'

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export const loginApi = (data) => {
  return request({
    url: '/api-uaa/oauth/token',
    method: 'post',
    headers: {
      Authorization: `Basic ${window.btoa('GccMonitor:Aiko@123!')}`
    },
    data: qs.stringify({
      username: data.username,
      password: data.password,
      validCode: data.validCode,
      deviceId: data.deviceId,
      grant_type: 'password_code'
    })
  })
}

/**
 * 注销API
 */
export const logoutApi = () => {
  return request({
    url: '/api/v1/auth/logout',
    method: 'delete'
  })
}

/**
 * 获取验证码
 */
export const getCaptchaApi = () => {
  return request({
    url: '/api/v1/auth/captcha',
    method: 'get'
  })
}

/**
 * @description
 * @export
 * @return {*}
 */
export const getUserInfo = () => {
  return request({
    url: `${userApi}/users/current`,
    method: 'get'
  })
}
